from rest_framework import serializers
from .models import Report, BodyType
from core.models import StudentProfile
from core.serializers import StudentReportSerializer

class BodyTypeSerializer(serializers.ModelSerializer):
    class Meta:
        model = BodyType
        fields = '__all__'

class ReportDetailSerializer(serializers.ModelSerializer):
    body_type_info = serializers.SerializerMethodField()
    student_info = serializers.SerializerMethodField()

    def get_body_type_info(self, obj):
        body_type = BodyType.objects.get(id=obj.body_type.id)
        return BodyTypeSerializer(body_type).data

    def get_student_info(self, obj):
        student_info = StudentProfile.objects.get(user__id=obj.user.id)
        return StudentReportSerializer(student_info).data

    class Meta:
        model = Report
        fields = ['report_id', 'createTime', 'body_type_info',
                  'student_info', 'height', 'weight',
                  'faceImg', 'tongueImg', 'type_stat',
                  'age']

class ReportBaseSerializer(serializers.ModelSerializer):
    class Meta:
        model = Report
        fields = ['report_id', 'type_stat', 'createTime']